//
//  CalendarViewOptions.swift
//  BocaiConsultant
//
//  Created by Sebarina Xu on 6/6/16.
//  Copyright © 2016 liufan. All rights reserved.
//pr

import UIKit
import CVCalendar
public class CalendarViewAppearance : NSObject {
    public var spaceBetweenDays : CGFloat = 2
    public var currentDaySelectedBgColor : UIColor = UIColor.colorFromCode(0x66ccff)
    public var currentDaySelectedTextColor : UIColor = UIColor.whiteColor()
    public var currentDayTextColor : UIColor = UIColor.redColor()
    public var currentDayBgColor : UIColor = UIColor.lightGrayColor()
    public var weekDaySelectedBgColor : UIColor = UIColor.colorFromCode(0x66ccff)
    public var weekDaySelectedTextColor : UIColor = UIColor.whiteColor()
    public var weekDayInTextColor : UIColor = UIColor.colorFromCode(0x2E3D50)
    public var weekDayOutTextColor : UIColor = UIColor.lightGrayColor()
    public var currentDayTextSize : CGFloat = 14
    public var weekDayTextSize : CGFloat = 14
    public var dayOfWeekTextColor : UIColor = UIColor.grayColor()
    public var firstDay : Weekday = .Monday
    public var weekdaySymbolType : WeekdaySymbolType = .Short
    public var dayOfWeekTextUppercase : Bool = true
    
    public func updateAppearance(delegate: CalendarViewAppearanceDelegate) {
        updateValue(delegate.currentDaySelectedBgColor?(), key: "currentDaySelectedBgColor")
        updateValue(delegate.spaceBetweenDays?(), key: "spaceBetweenDays")
        updateValue(delegate.currentDaySelectedTextColor?(), key: "currentDaySelectedTextColor")
        updateValue(delegate.currentDayTextColor?(), key: "currentDayTextColor")
        updateValue(delegate.currentDayBgColor?(), key: "currentDayBgColor")
        updateValue(delegate.weekDaySelectedBgColor?(), key: "weekDaySelectedBgColor")        
        updateValue(delegate.weekDaySelectedTextColor?(), key: "weekDaySelectedTextColor")
        updateValue(delegate.weekDayInTextColor?(), key: "weekDayInTextColor")
        updateValue(delegate.weekDayOutTextColor?(), key: "weekDayOutTextColor")
        updateValue(delegate.currentDayTextSize?(), key: "currentDayTextSize")
        updateValue(delegate.weekDayTextSize?(), key: "weekDayTextSize")
        
    }
    
    public func updateMenu(menuDelegate: CalendarMenuViewDelegate) {
        updateValue(menuDelegate.dayOfWeekTextColor?(), key: "dayOfWeekTextColor")
        updateValue(menuDelegate.dayOfWeekFont?(), key: "dayOfWeekTextFont")
        updateValue(menuDelegate.dayOfWeekTextUppercase?(), key: "dayOfWeekTextUppercase")
        if let day = menuDelegate.firstDay?() {
            self.firstDay = day
        }
        if let symbol = menuDelegate.weekdaySymbolType?() {
            self.weekdaySymbolType = symbol
        }
    }
    
    public func updateValue(value: AnyObject?, key: String) {
        if value != nil {
            self.setValue(value!, forKey: key)
        }
    }
 }

@objc public protocol CalendarViewAppearanceDelegate {
    optional func spaceBetweenDays() -> CGFloat
    optional func currentDaySelectedBgColor() -> UIColor
    optional func currentDaySelectedTextColor() -> UIColor
    optional func currentDayTextColor() -> UIColor
    optional func currentDayBgColor() -> UIColor
    optional func weekDaySelectedBgColor() -> UIColor
    optional func weekDaySelectedTextColor() -> UIColor
    optional func weekDayInTextColor() -> UIColor
    optional func weekDayOutTextColor() -> UIColor
    optional func currentDayTextSize() -> CGFloat
    optional func weekDayTextSize() -> CGFloat
}

@objc public protocol CalendarMenuViewDelegate {
    optional func firstDay() -> Weekday
    optional func dayOfWeekTextColor() -> UIColor
    optional func dayOfWeekTextUppercase() -> Bool
    optional func dayOfWeekFont() -> UIFont
    optional func weekdaySymbolType() -> WeekdaySymbolType
}

@objc public protocol CalendarViewDelegate {
    optional func didSelectDayView(dayView: DayView, animationDidFinish: Bool)
    optional func currentDateUpdated(date: CVDate)
    optional func didShowNextMonthView(date: NSDate)
    optional func didShowPreviousMonthView(date: NSDate)
}
